/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.mobbuzz.page.menu.inbox;

import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Container;
import com.sun.lwuit.Dialog;
import com.sun.lwuit.Font;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import edu.mobbuzz.bean.Message;
import edu.mobbuzz.page.menu.Menu;
import edu.mobbuzz.util.string.MenuString;
import java.util.Vector;

/**
 *
 * @author dailicious
 */
public class RecepientFormPage extends Menu{
    private Form contactForm;
    private Container contactPanel;
    private Label menuTitle;
    private TextArea contactTxtArea;
    private Command backCmd;
    private Command okCmd;
    private Message message;
    private Vector recepientArr;
    private int mode;
    private int messageType;
    
    public RecepientFormPage(){
        contactForm = new Form();
        contactPanel = new Container();
        menuTitle = new Label(getMenuTitle());
        
        contactTxtArea = new TextArea(5,25);

        okCmd = new Command("Ok"){
            public void actionPerformed(ActionEvent evt) {
                if(contactTxtArea.getText().equals(""))
                    Dialog.show("Error", "Mobbuzz ID must not be left blank", Dialog.TYPE_ERROR, null, "Ok", null);
                else
                    submitContact();
            }
        };

        backCmd = new Command("Back"){
            public void actionPerformed(ActionEvent evt) {
                backToRecepientPage();
            }
        };
    }

    public Vector getRecepientArr() {
        if(recepientArr==null){
            recepientArr = new Vector();
        }
        return recepientArr;
    }


    public void setRecepientArr(Vector recepientArr) {
        this.recepientArr = recepientArr;
    }
    
    public Message getMessage() {
        return message;
    }

    public void setMessage(Message message) {
        this.message = message;
    }

    public int getMode() {
        return mode;
    }

    public void setMode(int mode) {
        this.mode = mode;
    }

    public int getMessageType() {
        return messageType;
    }


    public void setMessageType(int messageType) {
        this.messageType = messageType;
    }
    
    public void showPage() {
        menuTitle.setAlignment(Component.CENTER);
        menuTitle.getStyle().setMargin(5, 0, 5, 0);
        menuTitle.getStyle().setFont(Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL));
        menuTitle.getStyle().setBgTransparency(0);
        
        contactTxtArea.getStyle().setMargin(10, 0, 10, 10);

        contactPanel.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        contactPanel.addComponent(menuTitle);
        contactPanel.addComponent(contactTxtArea);

        contactForm.setLayout(new BorderLayout());
        contactForm.addComponent(BorderLayout.CENTER, contactPanel);
        contactForm.addCommand(backCmd);
        contactForm.addCommand(okCmd);
        contactForm.setCommandListener(getActionlistener());
        contactForm.show();
    }

    public void submitContact(){
        if(!getRecepientArr().contains(contactTxtArea.getText())){
            getRecepientArr().addElement(contactTxtArea.getText());
        }
        RecepientListPage recepientListPage = new RecepientListPage();
        recepientListPage.setExitCmd(getExitCmd());
        recepientListPage.setMessaging(getMessaging());
        recepientListPage.setActionlistener(getActionlistener());
        recepientListPage.setMessage(getMessage());
        recepientListPage.setMode(getMode());
        recepientListPage.setRecepientArr(getRecepientArr());
        recepientListPage.setMessageType(getMessageType());
        recepientListPage.showPage();
    }
    
    public void backToRecepientPage(){
        RecepientPage contactPage = new RecepientPage();
        contactPage.setExitCmd(getExitCmd());
        contactPage.setMessaging(getMessaging());
        contactPage.setActionlistener(getActionlistener());
        contactPage.setMessage(getMessage());
        contactPage.setRecepientArr(getRecepientArr());
        contactPage.setMode(getMode());
        contactPage.setMessageType(getMessageType());
        contactPage.showPage();
    }
    
    public String getMenuTitle() {
        return MenuString.ENTER_CONTACT_ID;
    }



}
